#ifndef PATIENT_APPOINTMENTWIDGET_H
#define PATIENT_APPOINTMENTWIDGET_H

#include <QWidget>
#include <QJsonObject>
#include <QPushButton>
#include "../../../Common/models.h"
#include "../../../Common/protocol.h"

namespace Ui {
class PatientAppointmentWidget;
}

class PatientAppointmentWidget : public QWidget {
    Q_OBJECT
    
public:
    explicit PatientAppointmentWidget(const Patient& patient, QWidget *parent = nullptr);
    ~PatientAppointmentWidget();
    
private slots:
    void on_departmentCombo_currentIndexChanged(int index);
    void on_makeAppointmentButton_clicked();
    void on_refreshButton_clicked();
    void on_viewDetailButton_clicked();
    void on_doctorTable_cellDoubleClicked(int row, int column);
    void onMessageReceived(MessageType type, const QJsonObject& data);
    void onCancelAppointmentClicked();
    void onChatWithDoctorClicked();
    void onFilterChanged();
    void onSelectTimeButtonClicked();
    
private:
    void loadDepartments();
    void loadDoctors(int departmentId);
    void loadMyAppointments();
    void updateDoctorTable(const QJsonArray& doctors);
    void updateAppointmentTable(const QJsonArray& appointments);
    void showDoctorDetail(int row);
    void updateTimeButtonText();
    
    Ui::PatientAppointmentWidget *ui;
    Patient m_patient;
    QList<Doctor> m_doctors;  // 存储当前医生列表
    
    // 预约时间选择
    QPushButton *m_selectTimeButton;
    QDateTime m_selectedDateTime;
};

#endif // PATIENT_APPOINTMENTWIDGET_H

